﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        /* An anonymous function, executed immediately. */
        (function () {
            var foo = 10;
            var bar = 2;
            //alert(foo * bar);
        })();

        /* An anonymous function with arguments. */
        (function (foo, bar) {
            //alert(foo * bar);
        })(10, 2);

        /* An anonymous function used as a closure. */
        var baz;
        (function () {
            var foo = 10;
            var bar = 2;
            baz = function () {
                return foo * bar;
            };
        })();
       
        //giving attributes to functions:
        function displayError(message) {
            displayError.numTimesExecuted++;
            alert(message);
        };
        displayError.numTimesExecuted = 0;

        /* Class Person. */
        function Person(name, age) {
            this.name = name;
            this.age = age;
        }
        Person.prototype = {
            getName: function () {
                return this.name;
            },
            getAge: function () {
                return this.age;
            }
        }

        $(function () {
            //alert(baz());

            //            displayError("1");
            //            displayError("2");
            //            alert(displayError.numTimesExecuted);

            /* Instantiate the class. */
            var alice = new Person('Alice', 93);
            var bill = new Person('Bill', 30);
            /* Modify the class. */
            Person.prototype.getGreeting = function () {
                return 'Hi ' + this.getName() + '!';
            };
            /* Modify a specific instance. */
            alice.displayGreeting = function () {
                alert(this.getGreeting());
            }

            alice.displayGreeting();
        });
    </script>
</head>
<body>
    <div id="content">
    </div>
</body>
</html>
